/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.vsu.cs.piit.vokod.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Галчонок
 */
@Entity
@Table(name = "treatment")
@NamedQueries({@NamedQuery(name = "Treatment.findAll", query = "SELECT t FROM Treatment t"), @NamedQuery(name = "Treatment.findByTreatmentId", query = "SELECT t FROM Treatment t WHERE t.treatmentId = :treatmentId"), @NamedQuery(name = "Treatment.findByName", query = "SELECT t FROM Treatment t WHERE t.name = :name"), @NamedQuery(name = "Treatment.findByCode", query = "SELECT t FROM Treatment t WHERE t.code = :code")})
public class Treatment implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "treatment_id")
    private Integer treatmentId;
    @Column(name = "name")
    private String name;
    @Column(name = "code")
    private String code;

    @JoinColumn(name = "group_of_treatment_id", referencedColumnName = "group_of_treatment_id")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private GroupOfTreatment groupOfTreatment;

//    @OneToMany(cascade = CascadeType.ALL, mappedBy = "treatment", fetch = FetchType.LAZY)
//    private List<Pacient> pacientsCollection;

    public Treatment() {
    }

    public Treatment(Integer treatmentId) {
        this.treatmentId = treatmentId;
    }

    public Integer getTreatmentId() {
        return treatmentId;
    }

    public void setTreatmentId(Integer treatmentId) {
        this.treatmentId = treatmentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public GroupOfTreatment getGroupOfTreatment() {
        return groupOfTreatment;
    }

    public void setGroupOfTreatment(GroupOfTreatment groupOfTreatment) {
        this.groupOfTreatment = groupOfTreatment;
    }

//    public List<Pacient> getPacientCollection() {
//        return pacientsCollection;
//    }
//
//    public void setPacientCollection(List<Pacient> pacientsCollection) {
//        this.pacientsCollection = pacientsCollection;
//    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (treatmentId != null ? treatmentId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Treatment)) {
            return false;
        }
        Treatment other = (Treatment) object;
        if ((this.treatmentId == null && other.treatmentId != null) || (this.treatmentId != null && !this.treatmentId.equals(other.treatmentId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getCode()+". "+getName();
    }

}
